<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>登录</title>
    </head>
    <body>
        <form action="#">
            <h1>登录</h1>
            <div>
                <label for="username">用户名：</label>
                <input id="username" type="text" />
            </div>
            <div>
                <label for="pwd">密码：</label>
                <input id="pwd" type="password" />
            </div>

            <input id="submitBtn" type="button" value="提交" />
        </form>
        <script src="../js/mock-min.js"></script>
        <script src="./data.js"></script>
        <script src="./ajax.js"></script>
        <script>
            let submitBtn = document.getElementById("submitBtn");
            let username = document.getElementById("username");
            let pwd = document.getElementById("pwd");

            submitBtn.onclick = function () {
                ajax({
                    type: "post",
                    url: "/login",
                    data: {
                        username: username.value,
                        pwd: pwd.value,
                    },
                    success(res) {
                        if(res.status == 1){
                            alert("登录成功");
                        }else{
                            alert("登录失败");
                        }
                    },
                });
            };
        </script>
    </body>
</html>
